package cn.bingo.yunsj.controller;

import bingo.link.sdk.handler.uam.UamUserHandler;
import cn.bingo.yunsj.common.StateCode;
import cn.bingo.yunsj.common.result.Response;
import cn.bingo.yunsj.domain.RpNotSend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@Controller
public class UserController {

    private static String username = "";

    @Autowired
    private HttpServletResponse response;

    @RequestMapping(value = "/cookie",method = RequestMethod.GET)
    @ResponseBody
    public Response setCookie(){
        UamUserHandler uamUserHandler = new UamUserHandler();
        Cookie cookie = new Cookie("username",uamUserHandler.getCurrentUser().getName());
        username = uamUserHandler.getCurrentUser().getName();
        List<String> list = new ArrayList<>();
        list.add(username);
        response.addCookie(cookie);
        return new Response(StateCode.SEARCH_SUCCESS, (long) list.size(),list);
    }
}
